package com.jacky.二叉树;

import java.util.ArrayList;
import java.util.List;

public class 二叉树后序遍历_145 {

    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        postorder(root, list);
        return list;
    }
    public void postorder(TreeNode root,List<Integer> list){
        //推出递归方法的条件
        if (root ==null){
            return;
        }
        //左节点
        postorder(root.left,list);
        //右节点
        postorder(root.right,list);
        //先把跟节点放到list集合里面去
        list.add(root.val);
    }
}
